import plotly.express as px
import pandas as pd

import json
import eq_explore_data as ed

#探索数据的结构
filename='D:\GITEE\study_code\eq_data_30_day_m1.json'
with open(filename) as f:
    all_eq_data=json.load(f)

all_eq_dicts=all_eq_data['features']

mags,titles,lons,lats=[],[],[],[]
for eq_dict in all_eq_dicts:
    mags.append(eq_dict['properties']['mag'])
    titles.append(eq_dict['properties']['title'])
    lons.append(eq_dict['geometry']['coordinates'][0])
    lats.append(eq_dict['geometry']['coordinates'][1])

#根据json文件自动生成标题
json_title=all_eq_data['metadata']['title']

data=pd.DataFrame(
    data=zip(lons,lats,titles,mags),columns=['经度','纬度','位置','震级']
)

fig=px.scatter(
    data,
    x='经度',
    y='纬度',
    range_x=[-200,200],
    range_y=[-90,90],
    width=800,
    height=800,
    title=json_title,
    size='震级',
    size_max=10,
    color='震级',
    hover_name='位置',
)
fig.write_html('global_earthquakes.html')
fig.show()